package com.express.core.controller;

import com.express.common.SysParamterUtil;
import com.express.common.WebSocketServer;
import com.express.constants.Constants;
import com.express.entity.Test;
import com.express.service.ITestService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 测试类
 */
//@Api(tags = "测试用例")
//@ApiIgnore //是否跳过
@Controller
public class TestController{

    private static final Logger logger = LoggerFactory.getLogger(TestController.class);

    @Autowired
    @Qualifier("testServiceImpl")
    ITestService testService;

    @Autowired
    @Qualifier("twoTestServiceImpl")
    ITestService twotestService;

    @Autowired
    SysParamterUtil sysParamterUtil;
    @Autowired
    private WebSocketServer webSocket;
    /**
     * 测试请求
     * @return
     */
//    @ApiOperation(value = "测试发送消息",notes = "puttest测试说明2")
    @GetMapping(value="/test")
//    @ApiResponse(code = 200,message = "不为空则成功",response=String.class)
    @ResponseBody
    public String test(){
        logger.info("is test");
        webSocket.sendAllMessage("2222 test socket");
        testService.sayHi();
        twotestService.sayHi();
        Object parametValue = sysParamterUtil.getParametValue(Constants.ENV_ORDER, true);
        sysParamterUtil.setParametValue(Constants.ENV_ORDER, parametValue);
        String temp = "测试访求" + parametValue;
        return temp;
    }
    /**
     * 测试保存
     * @return
     */
//    @ApiOperation(value = "测试保存")
    @RequestMapping("/save")
    @ResponseBody
    public String save(){
        Test test = new Test();
        test.setId(10);
        test.setName("11");
        testService.save(test);
        logger.info("is save");
        return "1";
    }
    /**
     * 测试更新
     * @return
     */
//    @ApiOperation(value = "测试更新")
    @RequestMapping("/update")
    @ResponseBody
    public String update(){
        logger.info("is update");
        return "2";
    }
    /**
     * 测试查询
     * @return
     */
//    @ApiOperation(value = "测试查询")
    @RequestMapping("/get")
    @ResponseBody
    public List<Test> get(){
        List<Test> object = testService.query();
        logger.info("is get");
        return object;
    }
    /**
     * 测试跳到首页
     * @return
     */
//    @ApiImplicitParam(name = "name",value = "姓名",required = true)
//    @ApiOperation(value = "测试跳到首页")
    @RequestMapping("/toindex")
    public String index(){
        logger.info("is index");
        return "toindex";
    }

//    @ApiImplicitParam(name = "name",value = "姓名",required = true)
//    @ApiOperation(value = "向客人问好")
    @GetMapping("/sayHi")
    public ResponseEntity<String> sayHi(@RequestParam(value = "name")String name){
        return ResponseEntity.ok("Hi:"+name);
    }
}
